﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LocalFileSearchDll
{
    public static class SimpleSearchHelper
    {
        public static IList<FileInfo> Search(string targetDir,string content)
        {
            var result = new List<FileInfo>();
            try
            {
                if(Directory.Exists(targetDir))
                {
                    var scanner = new MFTScanner();
                    var files = scanner.EnumerateFiles(@"F:\");

                    foreach (var file in files)
                    {
                        //过滤掉非法文件
                        if (file.Contains("$")) continue;
                        
                        //在给定目录下搜索，只要从前往后判断就可以
                        if(file.StartsWith(targetDir,true,CultureInfo.CurrentCulture))
                        {
                            if (file.IndexOf(content, 0, StringComparison.OrdinalIgnoreCase) >= 0)
                            {
                                result.Add(new FileInfo(file));
                            }
                        }
                    }

                }
            }
            catch (Exception ex)
            {

            }

            return result;
        }
    }
}
